package com.contest.controller;

import com.contest.util.DateUtil;
import com.contest.util.RandomUtil;
import com.contest.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import redis.clients.jedis.Jedis;

import java.util.Map;
import java.util.Set;

@RequestMapping("/data")
@ResponseBody
@Controller
public class DataController {
    @Autowired
    private RedisUtil redisUtil;

    @RequestMapping("/pushData")
    public Map<String, String> pushData(String gameName) {
//        Jedis redis = redisUtil.getJedis();
        if ("wzry".equals(gameName)) {
            Map<String, String> temp = RandomUtil.king();
            Set<String> keys = temp.keySet();
//            for (String key : keys) {
//                redis.hset("王者荣耀", key, temp.get(key));
//                redis.expire("王者荣耀", DateUtil.getTodayTimeDifference());
//            }
//            redisUtil.returnResource(redis);
            return temp;
        } else if ("yxlm".equals(gameName)) {
            Map<String, String> temp = RandomUtil.hero();
            Set<String> keys = temp.keySet();
//            for (String key : keys) {
//                redis.hset("英雄联盟", key, temp.get(key));
//                redis.expire("英雄联盟", DateUtil.getTodayTimeDifference());
//            }
//            redisUtil.returnResource(redis);
            return temp;
        } else if ("hyxd".equals(gameName)) {
            Map<String, String> temp = RandomUtil.wilderness();
            Set<String> keys = temp.keySet();
//            for (String key : keys) {
//                redis.hset("荒野行动", key, temp.get(key));
//                redis.expire("荒野行动", DateUtil.getTodayTimeDifference());
//            }
//            redisUtil.returnResource(redis);
            return temp;
        }
        return null;
    }
}
